package org.coderk.mybatis.controller.user;

import org.coderk.mybatis.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Time;
import java.util.concurrent.TimeUnit;

/**
 * @author: TanJingyu
 * @create: 2021-06-29 10:43
 **/
@Service
@Transactional(rollbackFor = RuntimeException.class)
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
//    @Async
    public void update() throws InterruptedException {
        Integer grade = jdbcTemplate.queryForObject("SELECT grade FROM user WHERE id = 1", Integer.class);
        TimeUnit.SECONDS.sleep(3);
        System.out.println("更新。。。。");
        jdbcTemplate.update("UPDATE user SET grade = ?", grade + 1);
//        System.out.println(userMapper.update());
    }

    @Override
    public void insert() {

    }
}
